package com.copa.module.order.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.copa.domain.ResponseDto;
import com.copa.module.order.domain.entity.OrderGoodsEntity;
import com.copa.module.order.mapper.OrderGoodsDao;
import com.copa.module.order.service.OrderGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @author copa
 * @createDate 2021-01-25 15:01
 * @function
 */
@Service
public class OrderGoodsServiceImpl implements OrderGoodsService {

    @Autowired
    private OrderGoodsDao orderGoodsDao;

    @Override
    public ResponseDto<Boolean> addOrderGoods(List<OrderGoodsEntity> orderGoodsEntities) {
        Boolean flag = orderGoodsDao.insertOrderGoods(orderGoodsEntities);
        if (flag) {
            return ResponseDto.success();
        }
        return ResponseDto.errorMsg("系统繁忙，请稍后再下单！");
    }

    @Override
    public ResponseDto<OrderGoodsEntity> findOrderGoodsByMap(Map<String, Object> selectCondition) {
        List<OrderGoodsEntity> orderGoodsEntities = orderGoodsDao.selectByMap(selectCondition);
        if (ObjectUtil.isNotNull(orderGoodsEntities.get(0))) {
            return ResponseDto.success(orderGoodsEntities.get(0));
        }
        return ResponseDto.errorMsg("查找不到该子订单！");
    }

    @Override
    public ResponseDto<Boolean> updateByOrderGoods(OrderGoodsEntity orderGoods) {
        int update = orderGoodsDao.updateById(orderGoods);
        if (update > 0) {
            return ResponseDto.success();
        }
        return ResponseDto.errorMsg("系统繁忙，请稍后再试！");
    }
}
